function Room(){
	this.publicBlogs=[];
	this.nodes=[];
	this.map=null;
	this.marker=null;
	this.circle=null;
	this.rectangle=null;
	this.polyline=null;
	this.polygon=null;
	this.infowindow=new google.maps.InfoWindow();
	this.adapter = new ClientAdapter("/CoupledObjectWebServer/");
	this.adapter.joinSession("feed");
	this.adapter.start(500);
	
	this.personalAdapter = new ClientAdapter("/CoupledObjectWebServer/");
	this.personalAdapter.joinSession("sync");
	var userId = this.personalAdapter.userId
	
	this.personalAdapter.leaveSession();
	this.personalAdapter.joinSession("intop-" + userId);
	this.personalAdapter.start(500);
	
	this.selected=null;
	this.couple();
}

Room.prototype.getNewId = function(){
	return Math.floor((Math.random()*100000)+1)+'_'+this.adapter.clientId;
};

Room.prototype.publish = function(blogId,lat,lng,title,description,files,tags,time,userId){
	this.addFeed(blogId,title,tags);
};

Room.prototype.publishCircle = function(blogId,lat,lng,radius,title,description,files,tags,time,userId){
	this.addFeed(blogId,title,tags);
};

Room.prototype.publishRectangle = function(blogId,boundsArray,title,description,files,tags,time,userId){
	this.addFeed(blogId,title,tags);
};

Room.prototype.publishPolyline = function(blogId,pathArray,length,title,description,files,tags,time,userId){
	this.addFeed(blogId,title,tags);
};

Room.prototype.publishPolygon = function(blogId,pathArray,length,title,description,files,tags,time,userId){
	this.addFeed(blogId,title,tags);
};

Room.prototype.addFeed = function(blogId,title,tags){	
	sys.addNode(title,{color:"orange", id:blogId});
	if(tags.length==0){
		sys.addEdge("without tags",title);	
	}else{
		for(var i=0;i<tags.length;i++){		
			sys.addEdge(tags[i],title);		
		}
	}
	var i=this.nodes.length;
	this.nodes[i]=new Node(blogId,title);
};
Room.prototype.addFeedTag = function(nearestName,nodeFromName){
	sys.addEdge(nearestName,nodeFromName);
};

Room.prototype.addFeedFeed = function(tagName,nodeFromName, selectedNodeName){
	sys.addNode(tagName,{color:"#62E647",shape:"dot", alpha:1});           		  
	sys.addEdge(tagName,nodeFromName);
	sys.addEdge(tagName,selectedNodeName);
	tagsList.push(tagName);
};

Room.prototype.select = function(blogId){
	if (this.selected == blogId)
		return;
	this.selected = blogId;
};
Room.prototype._doSelect = function(blogId){
	
	if(this.selected==blogId)
		return;
	this.selected=blogId;
	var nodeName=null;
	for(var i=0;i<this.nodes.length;i++){
		if(this.nodes[i].id==blogId){
			nodeName=this.nodes[i].name;
			break;
		}
	}
	sys.eachNode(function(node, pt){
		if(node.data.shape==null)
			node.data.color="orange"
    })
	var node=sys.getNode(nodeName);
	node.data.color="blue";
	var tag=sys.getEdgesTo(nodeName)[0].source;
	var s=sys.toScreen(tag.p);
	var e = jQuery.Event( "mousemove", { pageX: s.x, pageY: s.y } );
	$("#sitemap").trigger(e);
}

Room.prototype.couple=function(){
	this.adapter.coupleObject("room",this,{
		messageType:"EVENT",
		explicitMapping:["publish","publishCircle","publishRectangle",
		                 "publishPolyline","publishPolygon","addFeedTag","addFeedFeed"]
	});
	this.personalAdapter.coupleObject("room", this, {
		messageType : "STATE",
		explicitMapping : [ 'select' ],
		getElementState:function(){
			return {selected:this.selected};
		},
		setElementState:function(state){
			this._doSelect(state.selected);
		}

	});
};